<?php
/**
 * Created by PhpStorm.
 * User: 69548
 * Date: 2018/7/28
 * Time: 10:17
 */

namespace app\api\controller;

use app\api\model\Comment as M;


class Comment extends Base
{


    public function index(){

      $goods_id=  input('goods_id');
        $shu=[];
            $m=new M();
            if (!empty($goods_id)){
                $comment=$m
                    ->alias('a')
                    ->join('member d','a.member_id=d.member_id')
                    ->join('attachment b','b.id=d.thumb')
                    ->where('a.goods_id',$goods_id)
                    ->where('a.comment_status',2)
                    ->field('a.content,a.creattime,d.member_nickname,b.filepath as touxiang,a.comment_img')
                    ->order('a.creattime desc')
                    ->select();
                foreach ($comment as $k=> $v){

                    $comment[$k]['creattime']=  date("Y-m-d H:i:s",$v['creattime']);
                    $img=!empty($v['comment_img'])?explode(',',$v['comment_img']):'';
                    if ($img!=''){
                        $comment[$k]['comment_img']= array_filter($img);
                    }else{
                        $comment[$k]['comment_img']= '';
                    }
                }
                if ($comment==true){
                    $shu=[
                        'code'=>0,
                        'msg'=>'ok',
                        'data'=>$comment
                    ];
                }else{
                    $shu=[
                        'code'=>101,
                        'msg'=>'还没有评论哦!',
                    ];
                }
            }else{
                $shu=[
                    'code'=>101,
                    'msg'=>'参数错误',
                ];
            }
        return json_encode($shu);

    }



    public function comments(){





    }

















}